﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Web;
using ECCIT.Extension.Weibo_v2.Common;
using OgilvyOne.BLL;
using OgilvyOne.Model;
using OgilvyOne.UKNow.Utility;
using OgilvyOne.UKNow.Mobile.Model.MyCalendar;
using OgilvyOne.UKNow.Mobile.Utilities;

namespace OgilvyOne.UKNow.Mobile.APIs.City
{
    using DCity = OgilvyOne.UKNow.Mobile.Model.MyCalendar.City;

    public class GetEventCity : IHttpHandler
    {
        public bool IsReusable
        {
            get { return true; }
        }

        public void ProcessRequest(HttpContext context)
        {
            try
            {
                List<DictionaryManageModel> cities = DictionaryUtil.GetCityModels();
                string arr = "北京,上海,广州,澳门,长沙,成都,重庆,贵阳,杭州,香港,兰州,南京,苏州,青岛,深圳,天津,武汉,周庄同里,中山";
                List<DCity> models = new List<DCity>();
                foreach (var v in arr.Split(','))
                {
                    var s = v.ToString();
                    var city = cities.FirstOrDefault(a => a.Cnname.Trim() == v.ToString());
                    DCity mCity = new DCity();
                    mCity.cityid = city.Cid;
                    mCity.cnname = city.Cnname;
                    mCity.enname = city.Enname;
                    models.Add((mCity));
                }
                //foreach (DictionaryManageModel city in cities)
                //{
                //    DCity mCity = new DCity();
                //    mCity.cityid = city.Cid;
                //    mCity.cnname = city.Cnname;
                //    mCity.enname = city.Enname;
                //    models.Add((mCity));
                //}

                if (models.Count > 0)
                {
                    string s = JsonSerializationHelper.ObjectToJson(models);
                    context.Response.Write(ResultUtility.ReturnResultJson("0", s, "获取城市列表成功"));
                }
            }
            catch (Exception ex)
            {
                context.Response.Write(ResultUtility.ReturnResultJson("-111", "", "获取城市列表失败 Message：" + ex.Message));
                throw;
            }
        }
    }
}
